
import * as CONSTANTS from "@constants/index";
interface iAlbum {
  audioVoList: any[]
}

export const getAlbumList =
  (target: any, prop: string = 'audioVoList') =>
    target[prop] ? target[prop] : [];

export const filterProps = (list: [], props: any[]) => list.map(x => {
  let result: any = {};
  Object.keys(x).forEach(k => props.includes(k) ? result[k] = x[k] : null)
  return result;
})

export const addDefaultDescription = (list: any[], defaults: any[]) => list.map(x => {
  let defaultDescription = defaults.find(v => v.name === x.name);
  let description = x['description'];
  if (!description && defaultDescription) description = defaultDescription['description'];
  if (!defaultDescription) description = "";
  return {
    ...x,
    description
  };
})
// ${CONSTANTS.VAR_QUALITY}
export const addIndex = (list: []) => list.map((x: any, index: number) => ({ ...x, index }))
export const addQuality = (list: []) => list.map((x: any, index: number) => ({ ...x, coverImage: `${x.coverImage}${CONSTANTS.VAR_QUALITY}` }))
